#断言： assert: 对比预期结果和实际结果，不满足断言则抛出asserterror
#用法：      assert"登陆成功"=="登录失败" , "登录失败"
#          实际结果  操作符  预期结果  , 异常描述信息
#1.操作符
#常用：比较运算符 > >= < <= == !=
#判断值是否为空， is None  , is not None
#常用：包含 或者 不包含 : in , not in
#判断逻辑值 True False
      # assert result
      # True
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
class TestOA:
    driver = None
    def setup_method(self):
        TestOA.driver = webdriver.Chrome()
        TestOA.driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
    def teardown_method(self):
        TestOA.driver.quit()
    @pytest.mark.run(order=3)
    def test_login_success(self):
        # driver = webdriver.Chrome()
        # driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
        # sleep(2)
        TestOA.driver.maximize_window()
        sleep(2)
        TestOA.driver.find_element(By.ID,"account").send_keys("123456")
        sleep(2)
        TestOA.driver.find_element(By.NAME,"password").send_keys("123456")
        sleep(2)
        TestOA.driver.find_element(By.ID,"submit").click()
        sleep(2)
        text=TestOA.driver.find_element(By.LINK_TEXT,"签退").text
        assert text=="签退","登陆失败"
        # driver.quit()

    @pytest.mark.run(order=2)
    def test_login_fail1(self):

        # driver = webdriver.Chrome()
        # driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
        # sleep(2)
        TestOA.driver.maximize_window()
        sleep(2)
        TestOA.driver.find_element(By.ID,"account").send_keys("")
        sleep(2)
        TestOA.driver.find_element(By.NAME,"password").send_keys("123456")
        sleep(2)
        TestOA.driver.find_element(By.ID,"submit").click()
        sleep(2)
        text=TestOA.driver.find_element(By.XPATH,"/html/body/div[2]/div/div/div[1]/div").text
        assert text=="登录失败，请检查您的成员名或密码是否填写正确。","输入空的用户名,进行登录,用例执行失败"
        # driver.quit()
# except AssertionError as e:
#     raise e
# except Exception as e:
#       print(e)
#       raise e
    @pytest.mark.run(order=1)
    def test_login_fail2(self):

        # driver = webdriver.Chrome()
        # driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
        # sleep(2)
        TestOA.driver.maximize_window()
        sleep(2)
        TestOA.driver.find_element(By.ID,"account").send_keys("123456")
        sleep(2)
        TestOA.driver.find_element(By.NAME,"password").send_keys("")
        sleep(2)
        TestOA.driver.find_element(By.ID,"submit").click()
        sleep(2)
        text=TestOA.driver.find_element(By.XPATH,"/html/body/div[2]/div/div/div[1]/div").text
        assert text == "登录失败，请检查您的成员名或密码是否填写正确。", "输入空的密码,进行登录,用例执行失败"
        # driver.quit()

if __name__ == '__main__':
    pass
    # test_login_success()
    # test_login_fail1()
    # test_login_fail2()